<template>
  <div>
    <el-dialog
      title="话题审核"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :lock-scroll="false"
      width="800px"
      @closed="resetForm('form')"
    >
      <div>
        <el-form ref="form" :rules="rules" :model="form" label-width="80px">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="审核" prop="auditStatus">
                <el-radio-group v-model="form.auditStatus">
                  <el-radio label="2">通过</el-radio>
                  <el-radio label="3">驳回</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="审核说明">
                <el-input
                  type="textarea"
                  :rows="10"
                  placeholder="请输入审核说明"
                  v-model="form.extFiled.auditReason"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="custom" v-preventReClick @click="submitForm('form')"
          >提 交</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        id: '',
        auditStatus: '2', //审核状态;1-待审核，2-审核通过，3-不通过
        extFiled: {
          auditReason: '',
        },
      },
      rules: {
        auditStatus: [
          { required: true, message: '请选择审核状态', trigger: 'blur' },
        ],
      },
    }
  },
  mounted() {
    this.$bus.$on('bbsAudit', this.init)
  },
  beforeDestroy() {
    this.$bus.$off('bbsAudit')
  },
  methods: {
    init(row) {
      this.form.id = row.id
      this.form.auditStatus = '2'
      this.form.extFiled.auditReason = ''
      this.dialogVisible = true
    },
    submitForm(form) {
      this.form.extFiled = JSON.stringify(this.form.extFiled)
      this.$refs[form].validate(async (valid) => {
        if (valid) {
          await this.$store.dispatch('updateBbsTopic', this.form)
          this.done()
        }
      })
    },
    done() {
      this.dialogVisible = false
      this.$bus.$emit('refreshBbsTopicList')
      this.$message({
        message: '操作成功',
        type: 'success',
      })
    },
    resetForm(form) {
      this.$refs[form].resetFields()
    },
  },
}
</script>
<style scoped lang="scss">
</style>